package infostroy.bookagolf.views;

import com.academysmart.bookagolf.i18n.Messages;
import com.academysmart.bookagolf.model.Statistic;
import com.academysmart.bookagolf.model.StatisticsEquipmentItem;
import com.academysmart.bookagolf.model.StatisticsEquipments;
import com.academysmart.bookagolf.model.StatisticsHoles;
import com.academysmart.bookagolf.model.StatisticsIncome;
import com.academysmart.bookagolf.provider.StatisticProvider;
import infostroy.bookagolf.common.Constants.Colors;
import infostroy.bookagolf.common.Constants.Dimensions;
import infostroy.bookagolf.common.Constants.Icons;
import infostroy.bookagolf.common.Constants.Sizes;
import infostroy.bookagolf.common.helpers.ComponentsHelper;
import infostroy.bookagolf.common.helpers.ImageHelper;
import infostroy.bookagolf.common.helpers.NumberFormateHelper;
import infostroy.bookagolf.common.helpers.ValidationHelper;
import infostroy.bookagolf.components.chart.GolfStatisticsChart;
import infostroy.bookagolf.components.controls.GolfRoundButton;
import infostroy.bookagolf.components.inputs.GolfCheckBox;
import infostroy.bookagolf.components.inputs.GolfComboBox;
import infostroy.bookagolf.components.panels.GolfPanelWithSlider;
import infostroy.bookagolf.components.panels.GolfRoundPanel;
import infostroy.bookagolf.components.panels.ScrollPanel;
import infostroy.bookagolf.components.widgets.GolfCalendar;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 * Created by Andrew on 28.02.14.
 */
public class StatisticsPanel extends GolfPanelWithSlider {
    private JLabel bookingLbl;
    private JLabel amountLbl;
    private JLabel proceedsLbl;

    private JPanel topReservationPanel;
    private GridLayout topReservationGL;
    private JPanel bookingAdditionalServicesPanel;
    private GridLayout bookingAdditionalServicesGL;

    private JLabel bookingAdditionalServices;

    private JPanel calendarNavigationPanel;
    private JPanel calendarControlsPanel;
    private static Calendar calendar = Calendar.getInstance();
    private static SimpleDateFormat calendarFormat = new SimpleDateFormat("yyyy | MMMM, dd", Locale.getDefault());
    private JLabel dateLabel;
    private JLabel dayFilterLbl;
    private JLabel weekFilterLbl;
    private JLabel monthFilterLbl;

    private JPanel graphPanel;
    private JLabel graphParametersLbl;
    private JLabel graphLbl;
    private JLabel tableLbl;

    private JPanel displayGraphPanel;

    private JPanel holderPanel;
    private ScrollPanel scrollPanel;
    private JLabel chosenDateFromLbl;
    private boolean isChosenDateFrom;
    private Date dateFrom;
    private JLabel chosenDateToLbl;
    private boolean isChosenDateTo;
    private Date dateTo;
    private JLabel dateFromLbl;
    private JLabel dateToLbl;
    private JButton calendarFromButton;
    private GolfCalendar calendarFromWidget = new GolfCalendar(calendarFromButton, new DateChangeListener());
    private JButton calendarToButton;
    private GolfCalendar calendarToWidget = new GolfCalendar(calendarToButton, new DateChangeListener());
    private JButton showButton;
    private JComboBox timeFromJCB;
    private JComboBox timeToJCB;
    private JLabel timeFromLbl;
    private JLabel timeToLbl;

    private JCheckBox select9HolesJCB;
    private JCheckBox select18HolesJCB;
    private JCheckBox selectAdditionalServicesJCB;
    private GolfStatisticsChart statisticsChart;
    private JPanel chartLegend;

    private static SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    private Statistic statistic;
    private ScrollPanel statisticScroll;

    private int currentDate;
    private boolean monthIncrement;
    private boolean dayIncrement;

    @Override
    protected void resizeChildren(int sliderPanel, JComponent pane, JLayeredPane parent) {
        super.resizeChildren(sliderPanel, pane, parent);
        scrollPanel.setBounds(0, 0, pane.getWidth(), scrollPanel
                .getHeight());
    }

    @Override
    protected void addSlidePanelComponents(JPanel panel) {
        panel.setLayout(new FlowLayout(FlowLayout.LEADING));

        panel.add(addChooseDatePanel());
        panel.add(addDateFromPanel());
        panel.add(addDateToPanel());
//        panel.add(addChooseTimePanel());
//        panel.add(addTimeFromPanel());
//        panel.add(addTimeToPanel());

        JLabel separatorLabel = new JLabel(new ImageIcon(ImageHelper
                .getInstance().loadImage(Icons.SLIDER_SEPARATOR)));
        separatorLabel.setHorizontalAlignment(SwingConstants.CENTER);
        JPanel separatorPanel = new JPanel(new BorderLayout());
        separatorPanel.setBackground(Colors.GREEN);
        separatorPanel.setPreferredSize(Dimensions.SLIDER_PANEL_ROW_DIM);
        separatorPanel.add(separatorLabel, BorderLayout.CENTER);
        panel.add(separatorPanel);

        panel.add(addCheckBoxPanel());

        JPanel emptyPanel = new JPanel();
        emptyPanel.setPreferredSize(Dimensions.SLIDER_PANEL_ROW_DIM);
        emptyPanel.setBackground(Colors.GREEN);
        panel.add(emptyPanel);

        showButton = new GolfRoundButton(Messages.StatisticsShow, Colors.BLUE_BUTTON_BACKGROUND, Colors.BUTTON_FOREGROUND
                , Colors.BLUE_BUTTON_BORDER, Dimensions.BLUE_BUTTON_DIM);
        showButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                fillStatisticsChart();
                initTopReservationPanelComponents();
                initBookingAdditionalServicesPanelComponents();
                statisticScroll.setPreferredSize(new Dimension(Sizes.CONTENT_PANEL_WIDTH - 100, 290));
                statisticScroll.setMaximumSize(new Dimension(Sizes.CONTENT_PANEL_WIDTH - 100, 290));
                statisticScroll.revalidate();
                calendar.setTime(dateFrom);
                fillDateRange();
                updateDate(false, false);
            }
        });
        JPanel buttonPanel = new JPanel(new BorderLayout());
        buttonPanel.setBackground(Colors.GREEN);
        buttonPanel.setPreferredSize(Dimensions.SLIDER_PANEL_WIDE_ROW_DIM);
        buttonPanel.add(showButton, BorderLayout.CENTER);
        panel.add(buttonPanel);
    }

    private void fillStatisticsChart() {
        loadStatistic();
        statisticsChart.setStatistic(statistic);
        statisticsChart.setDateRange(dateFrom, dateTo);
        statisticsChart.setDraw9HolesChart(select9HolesJCB.isSelected());
        statisticsChart.setDraw18HolesChart(select18HolesJCB.isSelected());
        statisticsChart.setDrawAdditionalServicesChart(selectAdditionalServicesJCB.isSelected());
        statisticsChart.testDraw();
    }

    private void loadStatistic() {
        if (ValidationHelper.isNullOrEmpty(dateFrom) && ValidationHelper.isNullOrEmpty(dateTo)) {
            Date date = new Date();
            isChosenDateFrom = true;
            chosenDateFromLbl.setText(dateFormat.format(date));
            dateFrom = date;

            isChosenDateTo = true;
            chosenDateToLbl.setText(dateFormat.format(date));
            dateTo = date;

        }

        statistic = StatisticProvider.getStatistic(dateFrom, dateTo);
    }


    private JPanel addChooseTimePanel() {
        JPanel panel = new JPanel();
        panel.setPreferredSize(new Dimension(Dimensions.SLIDER_PANEL_ROW_DIM.width, Dimensions.SLIDER_PANEL_ROW_DIM.height));
        panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
        panel.setBackground(Colors.GREEN);
        JLabel arrowDown = new JLabel(new ImageIcon(ImageHelper.getInstance()
                .loadImage(Icons.WHITE_ARROW_DOWN)));
        JLabel chooseTimeLbl = new JLabel(Messages.MainWindow_Time);
        chooseTimeLbl.setForeground(Color.WHITE);
        panel.add(chooseTimeLbl);
        panel.add(Box.createHorizontalGlue());
        panel.add(arrowDown);
        panel.add(Box.createRigidArea(new Dimension(Sizes.SLIDER_RIGHT_CONTENT_GAP, 0)));
        panel.setAlignmentX(LEFT_ALIGNMENT);
        return panel;
    }

    private JPanel addChooseDatePanel() {
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
        panel.setBackground(Colors.GREEN);

        JLabel chooseDateLbl = new JLabel(Messages.MainWindow_ChooseDate);
        chooseDateLbl.setForeground(Color.WHITE);

        panel.add(chooseDateLbl);
        panel.add(Box.createHorizontalGlue());
        JLabel arrowDown = new JLabel(new ImageIcon(ImageHelper.getInstance()
                .loadImage(Icons.WHITE_ARROW_DOWN)));

        panel.add(arrowDown);
        panel.add(Box.createRigidArea(new Dimension(Sizes.SLIDER_RIGHT_CONTENT_GAP, 0)));
        panel.setPreferredSize(Dimensions.SLIDER_PANEL_ROW_DIM);
        panel.setAlignmentX(LEFT_ALIGNMENT);
        return panel;
    }

    private JPanel addDateFromPanel() {
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
        panel.setBackground(Colors.GREEN);
        dateFromLbl = new JLabel();
        dateFromLbl.setForeground(Color.WHITE);
        dateFromLbl.setText(Messages.StatisticsFrom);
        JPanel dateFromPanel = new GolfRoundPanel();
        dateFromPanel.setLayout(new BoxLayout(dateFromPanel, BoxLayout.LINE_AXIS));
        dateFromPanel.setPreferredSize(new Dimension(Dimensions.SLIDER_PANEL_ROW_DIM.width - 10, Dimensions.SLIDER_PANEL_ROW_DIM.height));
        chosenDateFromLbl = new JLabel();
        dateFromPanel.add(chosenDateFromLbl);
        dateFromPanel.add(Box.createHorizontalGlue());
        calendarFromButton = ComponentsHelper.createButtonWithImg(ImageHelper
                .getInstance().loadImage(Icons.CALENDAR_ICON));
        calendarFromButton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                isChosenDateFrom = true;
                isChosenDateTo = false;
                calendarFromWidget.show();
            }
        });
        dateFromPanel.add(calendarFromButton);
        panel.add(dateFromLbl);
        panel.add(Box.createRigidArea(new Dimension(11, 5)));
        panel.add(dateFromPanel);
        panel.setPreferredSize(new Dimension(Dimensions.SLIDER_PANEL_ROW_DIM.width
                , Dimensions.SLIDER_PANEL_ROW_DIM.height));
        panel.setAlignmentX(LEFT_ALIGNMENT);
        return panel;
    }

    private JPanel addDateToPanel() {
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
        panel.setBackground(Colors.GREEN);
        dateToLbl = new JLabel();
        dateToLbl.setForeground(Color.WHITE);
        dateToLbl.setText(Messages.StatisticsTo);
        JPanel dateToPanel = new GolfRoundPanel();
        dateToPanel.setLayout(new BoxLayout(dateToPanel, BoxLayout.LINE_AXIS));
        dateToPanel.setPreferredSize(new Dimension(Dimensions.SLIDER_PANEL_ROW_DIM.width - 20, Dimensions.SLIDER_PANEL_ROW_DIM.height));
        chosenDateToLbl = new JLabel();
        dateToPanel.add(chosenDateToLbl);
        dateToPanel.add(Box.createHorizontalGlue());
        calendarToButton = ComponentsHelper.createButtonWithImg(ImageHelper
                .getInstance().loadImage(Icons.CALENDAR_ICON));
        calendarToButton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                isChosenDateFrom = false;
                isChosenDateTo = true;
                calendarToWidget.show();
            }
        });
        dateToPanel.add(calendarToButton);
        panel.add(dateToLbl);
        panel.add(Box.createRigidArea(new Dimension(4, 5)));
        panel.add(dateToPanel);
        panel.setAlignmentX(LEFT_ALIGNMENT);
        return panel;
    }

    private JPanel addTimeFromPanel() {
        JPanel panel = new JPanel();
        panel.setPreferredSize(new Dimension(Dimensions.SLIDER_PANEL_ROW_DIM.width, Dimensions.SLIDER_PANEL_ROW_DIM.height));
        panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
        panel.setBackground(Colors.GREEN);
        timeFromJCB = new GolfComboBox();
        timeFromLbl = new JLabel();
        timeFromLbl.setForeground(Color.WHITE);
        timeFromLbl.setText(Messages.StatisticsFrom);
        panel.add(timeFromLbl);
        panel.add(timeFromJCB);
        panel.add(timeFromLbl);
        panel.add(Box.createRigidArea(new Dimension(30, 5)));
        panel.add(timeFromJCB);
        panel.add(Box.createRigidArea(new Dimension(26, 5)));
        return panel;
    }

    private JPanel addTimeToPanel() {
        JPanel panel = new JPanel();
        panel.setPreferredSize(new Dimension(Dimensions.SLIDER_PANEL_ROW_DIM.width, Dimensions.SLIDER_PANEL_ROW_DIM.height));
        panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
        panel.setBackground(Colors.GREEN);
        timeToJCB = new GolfComboBox();
        timeToLbl = new JLabel();
        timeToLbl.setForeground(Color.WHITE);
        timeToLbl.setText(Messages.StatisticsTo);
        panel.add(timeToLbl);
        panel.add(Box.createRigidArea(new Dimension(24, 5)));
        panel.add(timeToJCB);
        panel.add(Box.createRigidArea(new Dimension(26, 5)));
        panel.setAlignmentX(LEFT_ALIGNMENT);
        return panel;
    }

    private JPanel addCheckBoxPanel() {
        select9HolesJCB = new GolfCheckBox();
        select9HolesJCB.setText(Messages.Statistics9Holes);

        select18HolesJCB = new GolfCheckBox();
        select18HolesJCB.setText(Messages.Statistics18Holes);

        selectAdditionalServicesJCB = new GolfCheckBox();
        selectAdditionalServicesJCB.setText(Messages.StatisticsAdditionalServices);

        JPanel checkBoxsPanel = new JPanel();
        GridLayout gridLayout = new GridLayout(3, 1);
        checkBoxsPanel.setLayout(gridLayout);
        checkBoxsPanel.setBackground(Colors.GREEN);


        checkBoxsPanel.add(select9HolesJCB);
        checkBoxsPanel.add(select18HolesJCB);
        checkBoxsPanel.add(selectAdditionalServicesJCB);
        checkBoxsPanel.setPreferredSize(new Dimension(Dimensions.SLIDER_PANEL_ROW_DIM.width
                , Dimensions.SLIDER_PANEL_ROW_DIM.height * 2));
        checkBoxsPanel.setAlignmentX(LEFT_ALIGNMENT);
        return checkBoxsPanel;
    }

    @Override
    protected void addContentPanelComponents(JPanel panel) {

        holderPanel = new JPanel();
        currentDate = 0;
        holderPanel.setLayout(new BoxLayout(holderPanel, BoxLayout.Y_AXIS));
        holderPanel.setSize(new Dimension(Sizes.CONTENT_PANEL_WIDTH, Sizes.CONTENT_PANEL_HEIGHT - 10));
        displayGraphPanel = new JPanel();
        displayGraphPanel.setLayout(new BoxLayout(displayGraphPanel, BoxLayout.PAGE_AXIS));
        displayGraphPanel.setBorder(new EmptyBorder(0, 0, 0, 60));

        scrollPanel = new ScrollPanel(holderPanel);
        scrollPanel.setBorder(new EmptyBorder(10, 40, 10, 10));
        scrollPanel.setPreferredSize(new Dimension(Sizes.CONTENT_PANEL_WIDTH, Sizes.CONTENT_PANEL_HEIGHT - 10));
        scrollPanel.setBounds(0, 0, Sizes.CONTENT_PANEL_WIDTH, Sizes.CONTENT_PANEL_HEIGHT - 10);
        scrollPanel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        loadStatistic();
        initTopReservationPanelComponents();
        initBookingAdditionalServicesPanelComponents();
        initCalendarPanelComponents();
        initGraphPanel();
        updateDate(false, false);

        addBookingAdditionalServicesPanelComponents();
        addCalendarPanelComponents();
        addGraphPanel();
        addDisplayGraphPanel();

        holderPanel.add(topReservationPanel);
        holderPanel.add(Box.createRigidArea(new Dimension(panel.getWidth(), 20)));
        holderPanel.add(bookingAdditionalServicesPanel);
        holderPanel.add(Box.createRigidArea(new Dimension(panel.getWidth(), 20)));
        holderPanel.add(calendarNavigationPanel);
        holderPanel.add(Box.createRigidArea(new Dimension(400, 20)));
        holderPanel.add(graphPanel);
        holderPanel.add(displayGraphPanel);
        fillStatisticsChart();
        panel.add(scrollPanel);

    }

    @Override
    protected void initList() {

    }

    @Override
    protected void initMembers() {

    }

    private void initTopReservationPanelComponents() {

        if (topReservationPanel == null) {
            topReservationPanel = new JPanel();
            topReservationGL = new GridLayout(8, 3);
            topReservationGL.setVgap(8);
            topReservationPanel.setLayout(topReservationGL);
        }
        if (topReservationPanel != null) {
            topReservationPanel.removeAll();
        }

        bookingLbl = new JLabel(Messages.StatisticsBooking);
        amountLbl = new JLabel(Messages.StatisticsAmountPerDaySlashMonth, JLabel.CENTER);
        amountLbl.setForeground(Colors.GREEN);
        proceedsLbl = new JLabel(Messages.StatisticsAmountFroThePeriod, JLabel.CENTER);
        proceedsLbl.setForeground(Colors.GREEN);
        topReservationPanel.add(bookingLbl);
        topReservationPanel.add(amountLbl);
        topReservationPanel.add(proceedsLbl);

        fillTopPanel();


    }

    private void fillTopPanel() {
        for (IncomeType type : IncomeType.values()) {
            addComponentToTopReservationPanel(topReservationPanel, type);
        }
    }

    private void addComponentToTopReservationPanel(JPanel panel, IncomeType type) {
        List<StatisticsIncome> incomeList = statistic.getIncomeList();
        List<StatisticsHoles> holesList = statistic.getHolesList();
        StatisticsIncome income = incomeList.get(currentDate);
        StatisticsHoles holes = holesList.get(currentDate);
        String strName = new String();
        String strValue = new String();
        String strSuma = new String();

        switch (type) {
            case INCOME:
                strName = type.getName();
                strValue = NumberFormateHelper.priceFormatDouble(income.getIncome());
                strSuma = NumberFormateHelper.priceFormatDouble(countingDoubleSumaElement(incomeList, type));
                break;
            case INCOME_ON_WEEKDAYS:
                strValue = NumberFormateHelper.priceFormatDouble(income.getIncomeOnWeekdays());
                strName = type.getName();
                strSuma = NumberFormateHelper.priceFormatDouble(countingDoubleSumaElement(incomeList, type));
                break;
            case INCOME_ON_WEEKENDS:
                strName = type.getName();
                strValue = NumberFormateHelper.priceFormatDouble(income.getIncomeOnWeekends());
                strSuma = NumberFormateHelper.priceFormatDouble(countingDoubleSumaElement(incomeList, type));
                break;
            case ORDER_ON_WEEKDAYS:
                strName = type.getName();
                strValue = NumberFormateHelper.priceFormatDouble(income.getOrderOnWeekdays());
                strSuma = NumberFormateHelper.priceFormatDouble(countingDoubleSumaElement(incomeList, type));
                break;
            case ORDER_ON_WEEKENDS:
                strName = type.getName();
                strValue = NumberFormateHelper.priceFormatDouble(income.getOrderOnWeekends());
                strSuma = NumberFormateHelper.priceFormatDouble(countingDoubleSumaElement(incomeList, type));
                break;
            case AMOUNT_9_HOLES:
                strName = type.getName();
                strValue = new String("" + holes.getAmount9Holes());
                strSuma = new String("" + countingIntegerSumaElement(holesList, type));
                break;
            case AMOUNT_18_HOLES:
                strName = type.getName();
                strValue = new String("" + holes.getAmount18Holes());
                strSuma = new String("" + countingIntegerSumaElement(holesList, type));
                break;
        }
        JLabel name = new JLabel(strName);
        JLabel value = new JLabel(strValue);
        value.setHorizontalAlignment(JLabel.CENTER);
        JLabel suma = new JLabel(strSuma);
        suma.setHorizontalAlignment(JLabel.CENTER);

        panel.add(name);
        panel.add(value);
        panel.add(suma);

    }

    private enum IncomeType {
        INCOME(Messages.StatisticsIncome),
        INCOME_ON_WEEKENDS(Messages.StatisticsIncomeOnWeekends),
        INCOME_ON_WEEKDAYS(Messages.StatisticsIncomeOnWeekdays),
        ORDER_ON_WEEKENDS(Messages.StatisticsOrderOnWeekends),
        ORDER_ON_WEEKDAYS(Messages.StatisticsOrderOnWeekdays),
        AMOUNT_9_HOLES(Messages.Statistics9Holes),
        AMOUNT_18_HOLES(Messages.Statistics18Holes);
        private String name;

        IncomeType(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        @Override
        public String toString() {
            return name;
        }
    }

    private double countingDoubleSumaElement(List<StatisticsIncome> list, IncomeType type) {
        double result = 0d;
        List<Double> statisticsIncomeValues = new ArrayList<>();
        switch (type) {
            case INCOME:
                statisticsIncomeValues = generateDoubleListStatisticsIncome(list, IncomeType.INCOME);
                break;
            case INCOME_ON_WEEKDAYS:
                statisticsIncomeValues = generateDoubleListStatisticsIncome(list, IncomeType.INCOME_ON_WEEKDAYS);
                break;
            case INCOME_ON_WEEKENDS:
                statisticsIncomeValues = generateDoubleListStatisticsIncome(list, IncomeType.INCOME_ON_WEEKENDS);
                break;
            case ORDER_ON_WEEKDAYS:
                statisticsIncomeValues = generateDoubleListStatisticsIncome(list, IncomeType.ORDER_ON_WEEKDAYS);
                break;
            case ORDER_ON_WEEKENDS:
                statisticsIncomeValues = generateDoubleListStatisticsIncome(list, IncomeType.ORDER_ON_WEEKENDS);
                break;
        }
        for (Double value : statisticsIncomeValues) {
            result = result + value;
        }
        return result;
    }

    private int countingIntegerSumaElement(List<StatisticsHoles> list, IncomeType type) {
        int result = 0;
        List<Integer> statisticsIncomeValues = new ArrayList<>();
        switch (type) {
            case AMOUNT_9_HOLES:
                statisticsIncomeValues = generateIntegerListStatisticsIncome(list, IncomeType.AMOUNT_9_HOLES);
                break;
            case AMOUNT_18_HOLES:
                statisticsIncomeValues = generateIntegerListStatisticsIncome(list, IncomeType.AMOUNT_18_HOLES);
                break;
        }
        for (Integer value : statisticsIncomeValues) {
            result = result + value;
        }
        return result;
    }

    private List<Double> generateDoubleListStatisticsIncome(List<StatisticsIncome> list, IncomeType type) {
        List<Double> resultList = new ArrayList<>();
        for (StatisticsIncome income : list) {
            switch (type) {
                case INCOME:
                    resultList.add(income.getIncome());
                    break;
                case INCOME_ON_WEEKDAYS:
                    resultList.add(income.getIncomeOnWeekdays());
                    break;
                case INCOME_ON_WEEKENDS:
                    resultList.add(income.getIncomeOnWeekends());
                    break;
                case ORDER_ON_WEEKDAYS:
                    resultList.add(income.getOrderOnWeekdays());
                    break;
                case ORDER_ON_WEEKENDS:
                    resultList.add(income.getOrderOnWeekends());
                    break;
            }
        }
        return resultList;
    }

    private List<Integer> generateIntegerListStatisticsIncome(List<StatisticsHoles> list, IncomeType type) {
        List<Integer> resultList = new ArrayList<>();
        for (StatisticsHoles holes : list) {
            switch (type) {
                case AMOUNT_9_HOLES:
                    resultList.add(holes.getAmount9Holes());
                    break;
                case AMOUNT_18_HOLES:
                    resultList.add(holes.getAmount18Holes());
                    break;
            }
        }
        return resultList;
    }

    private void initBookingAdditionalServicesPanelComponents() {

        bookingAdditionalServicesPanel = new JPanel();
        int rows = statistic.getStatisticsEquipments().get(0).getEquipmentItems().size() + 1;
        bookingAdditionalServicesGL = new GridLayout(rows, 3);
        bookingAdditionalServicesGL.setVgap(8);
        bookingAdditionalServicesPanel.setLayout(bookingAdditionalServicesGL);
        bookingAdditionalServices = new JLabel(Messages.StatisticsBookingAdditionalServices);
        bookingAdditionalServicesPanel.add(bookingAdditionalServices);
        bookingAdditionalServicesPanel.add(new JLabel(""));
        bookingAdditionalServicesPanel.add(new JLabel(""));
        fillBookingAdditionalServicesPanel();

    }


    private void fillBookingAdditionalServicesPanel() {
        List<StatisticsEquipments> equipments = statistic.getStatisticsEquipments();
        for (int i = 0; i < equipments.get(currentDate).getEquipmentItems().size(); i++) {
            String nameStr = equipments.get(currentDate).getEquipmentItems().get(i).getName();
            String valueStr = "" + equipments.get(currentDate).getEquipmentItems().get(i).getValue();
            String sumStr = "" + countingEquipmentsAmount(equipments, equipments.get(0).getEquipmentItems().get(i).getName());
            JLabel name = new JLabel(nameStr);
            JLabel value = new JLabel(valueStr);
            value.setHorizontalAlignment(JLabel.CENTER);
            JLabel sum = new JLabel(sumStr);
            sum.setHorizontalAlignment(JLabel.CENTER);
            bookingAdditionalServicesPanel.add(name);
            bookingAdditionalServicesPanel.add(value);
            bookingAdditionalServicesPanel.add(sum);
        }

    }

    private int countingEquipmentsAmount(List<StatisticsEquipments> list, String equipmentName) {
        int result = 0;
        for (StatisticsEquipments equipment : list) {
            for (StatisticsEquipmentItem item : equipment.getEquipmentItems()) {
                if (item.getName().equals(equipmentName)) {
                    result = result + item.getValue();
                }
            }
        }
        return result;
    }

    private void addBookingAdditionalServicesPanelComponents() {
    }

    private void initCalendarPanelComponents() {
        calendarNavigationPanel = new JPanel();
        calendarNavigationPanel.setLayout(new BoxLayout(calendarNavigationPanel, BoxLayout.LINE_AXIS));

        dayFilterLbl = new JLabel(Messages.StatisticsDayFilter);
        dayFilterLbl.setForeground(Colors.FILTER_LABEL);
        weekFilterLbl = new JLabel(Messages.StatisticsWeekFilter);
        weekFilterLbl.setForeground(Colors.FILTER_LABEL);
        monthFilterLbl = new JLabel(Messages.StatisticsMonthFilter);
        monthFilterLbl.setForeground(Colors.FILTER_LABEL);

        calendarControlsPanel = new JPanel();
        calendarControlsPanel.setLayout(new BoxLayout(calendarControlsPanel, BoxLayout.LINE_AXIS));
//        calendarControlsPanel.setMaximumSize(new Dimension(Dimensions.FRAME_DIM.width, calendarControlsPanel.getPreferredSize().height));
//        calendarControlsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
        JButton calendarPrevDate = ComponentsHelper.createButtonWithImg(ImageHelper
                .getInstance().loadImage(Icons.LEFT_BLACK_ARROW));
        calendarPrevDate.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                updateDate(false, true);
            }
        });
        JButton calendarNextDate = ComponentsHelper.createButtonWithImg(ImageHelper
                .getInstance().loadImage(Icons.RIGHT_BLACK_ARROW));
        calendarNextDate.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                updateDate(true, true);
            }
        });
        dateLabel = new JLabel();
        calendarControlsPanel.add(calendarPrevDate);
        calendarControlsPanel.add(dateLabel);
        calendarControlsPanel.add(calendarNextDate);
    }

    private void addCalendarPanelComponents() {
        calendarNavigationPanel.add(calendarControlsPanel);
//        calendarNavigationPanel.add(Box.createRigidArea(new Dimension(30, 5)));
//        calendarNavigationPanel.add(dayFilterLbl);
//        calendarNavigationPanel.add(Box.createRigidArea(new Dimension(30, 5)));
//        calendarNavigationPanel.add(weekFilterLbl);
//        calendarNavigationPanel.add(Box.createRigidArea(new Dimension(30, 5)));
//        calendarNavigationPanel.add(monthFilterLbl);
    }

    private void updateDate(boolean increment, boolean needIncrement) {

        if (needIncrement) {
            if (!monthIncrement) {
                if (!dayIncrement) {
                    if (increment) {
                        calendar.add(Calendar.DATE, 1);
                    } else {
                        calendar.add(Calendar.DATE, -1);
                    }
                } else {
                    Calendar temp = Calendar.getInstance();
                    if (increment) {
                        temp.setTime(dateTo);
                        if (calendar.before(temp)) {
                            currentDate++;
                            calendar.add(Calendar.DATE, 1);
                            initTopReservationPanelComponents();
                            initBookingAdditionalServicesPanelComponents();
                        }
                    } else {
                        temp.setTime(dateFrom);
                        if (calendar.after(temp)) {
                            currentDate--;
                            calendar.add(Calendar.DATE, -1);
                            initTopReservationPanelComponents();
                            initBookingAdditionalServicesPanelComponents();
                        }
                    }
                }

            } else {
                if (increment) {
                    if (calendar.getTime().getTime() < dateTo.getTime()) {
                        Calendar temp = Calendar.getInstance();
                        temp.setTime(dateTo);
                        if ((calendar.get(Calendar.YEAR) < temp.get(Calendar.YEAR)
                                || calendar.get(Calendar.YEAR) == temp.get(Calendar.YEAR))
                                && calendar.get(Calendar.MONTH) != temp.get(Calendar.MONTH)) {
                            currentDate++;
                            calendar.add(Calendar.MONTH, 1);
                            initTopReservationPanelComponents();
                            initBookingAdditionalServicesPanelComponents();
                        }
                    }
                } else {
                    if (calendar.getTime().getTime() > dateFrom.getTime()) {
                        currentDate--;
                        calendar.add(Calendar.MONTH, -1);
                        initTopReservationPanelComponents();
                        initBookingAdditionalServicesPanelComponents();
                    }
                }
            }
        }

        dateLabel.setText(calendarFormat.format(calendar.getTime()));
    }

    private void fillDateRange() {
        int monthFrom;
        int monthTo;
        int yearFrom;
        int yearTo;

        Calendar month = Calendar.getInstance();
        month.setTime(dateFrom);
        monthFrom = month.get(Calendar.MONTH) + 1;
        yearFrom = month.get(Calendar.YEAR);
        month.setTime(dateTo);
        monthTo = month.get(Calendar.MONTH) + 1;
        yearTo = month.get(Calendar.YEAR);


        if (yearFrom == yearTo) {
            if (monthFrom == monthTo) {
                monthIncrement = false;
                dayIncrement = true;
            } else if (monthTo == (monthFrom + 1)) {
                monthIncrement = false;
                dayIncrement = true;
            } else if (monthFrom < monthTo) {
                monthIncrement = true;
                dayIncrement = false;
            }
        } else if (yearFrom < yearTo) {
            monthIncrement = true;
            dayIncrement = false;
        }
    }

    private void initGraphPanel() {
        graphPanel = new JPanel();
        graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.X_AXIS));

        graphLbl = new JLabel(Messages.StatisticsGraph);
        graphLbl.setForeground(Colors.FILTER_LABEL);
        graphParametersLbl = new JLabel(Messages.StatisticsGraphParameters);
        graphParametersLbl.setForeground(Colors.FILTER_LABEL);
        tableLbl = new JLabel(Messages.StatisticsTable);
        tableLbl.setForeground(Colors.FILTER_LABEL);


    }

    private void addGraphPanel() {

        graphPanel.add(graphLbl);
        graphPanel.add(Box.createRigidArea(new Dimension(30, 5)));
        graphPanel.add(graphParametersLbl);
        graphPanel.add(Box.createRigidArea(new Dimension(30, 5)));
        graphPanel.add(tableLbl);

    }

    private void addDisplayGraphPanel() {

        statisticsChart = new GolfStatisticsChart();
        statisticsChart.setPreferredSize(new Dimension(Sizes.CONTENT_PANEL_WIDTH, 290));

        statisticScroll = new ScrollPanel(statisticsChart);
        statisticScroll.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 15));
        statisticScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        statisticScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        statisticScroll.setPreferredSize(new Dimension(Sizes.CONTENT_PANEL_WIDTH - 100, 290));
        statisticScroll.setBounds(0, 0, Sizes.CONTENT_PANEL_WIDTH - 100, 290);
        statisticScroll.setBorder(BorderFactory.createEmptyBorder());


        chartLegend = new JPanel(new FlowLayout());
        JPanel chartLineIncomeColor = new JPanel();
        chartLineIncomeColor.setSize(new Dimension(20, 10));
        chartLineIncomeColor.setBackground(Colors.GRAPH_INCOME_LINE_COLOR);

        JPanel chartLine9HolesColor = new JPanel();
        chartLine9HolesColor.setSize(new Dimension(20, 10));
        chartLine9HolesColor.setBackground(Colors.GRAPH_9HOLES_LINE_COLOR);

        JPanel chartLine18HolesColor = new JPanel();
        chartLine18HolesColor.setSize(new Dimension(20, 10));
        chartLine18HolesColor.setBackground(Colors.GRAPH_18HOLES_LINE_COLOR);

        JPanel chartLineAdditionalServicesColor = new JPanel();
        chartLineAdditionalServicesColor.setSize(new Dimension(20, 10));
        chartLineAdditionalServicesColor.setBackground(Colors.GRAPH_ADDITIONAL_SERVICES_COLOR);

        JLabel chartLineIncomeLbl = new JLabel();
        chartLineIncomeLbl.setText(Messages.StatisticsIncome);
        JLabel chartLine9HolesLbl = new JLabel();
        chartLine9HolesLbl.setText(Messages.Statistics9Holes);
        JLabel chartLine18HolesLbl = new JLabel();
        chartLine18HolesLbl.setText(Messages.Statistics18Holes);
        JLabel chartLineAdditionalServicesLbl = new JLabel();
        chartLineAdditionalServicesLbl.setText(Messages.StatisticsAdditionalServices);

        chartLegend.add(chartLineIncomeColor);
        chartLegend.add(chartLineIncomeLbl);
        chartLegend.add(Box.createRigidArea(new Dimension(10, 0)));
        chartLegend.add(chartLine9HolesColor);
        chartLegend.add(chartLine9HolesLbl);
        chartLegend.add(Box.createRigidArea(new Dimension(10, 0)));
        chartLegend.add(chartLine18HolesColor);
        chartLegend.add(chartLine18HolesLbl);
        chartLegend.add(Box.createRigidArea(new Dimension(10, 0)));
        chartLegend.add(chartLineAdditionalServicesColor);
        chartLegend.add(chartLineAdditionalServicesLbl);
        displayGraphPanel.add(statisticScroll);

        displayGraphPanel.add(chartLegend);
    }

    private class DateChangeListener implements GolfCalendar.CalendarCallback {

        @Override
        public void updateDate(Date date) {
            if (isChosenDateFrom) {
                chosenDateFromLbl.setText(dateFormat.format(date));
                dateFrom = date;
            }
            if (isChosenDateTo) {
                chosenDateToLbl.setText(dateFormat.format(date));
                dateTo = date;
            }
        }
    }

    @Override
    public void refreshPanelContent() {
        initBookingAdditionalServicesPanelComponents();
        initTopReservationPanelComponents();

    }


}

